////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifndef __WN_SCRIPTING_SCRIPTING_ENGINE_PUBLIC_H__
#define __WN_SCRIPTING_SCRIPTING_ENGINE_PUBLIC_H__

#include "WNCore/inc/WNTypes.h"
#include "WNScripting/inc/WNFunction.h"
#include "WNScripting/inc/WNTypeElement.h"

namespace WNScripting {

    typedef WN_VOID* (*WNScriptAllocFunc)(WN_SIZE_T);
    typedef WN_VOID  (*WNScriptFreeFunc)(WN_VOID*);
    typedef WN_VOID* (*WNScriptAlignedMallocFunc)(WN_SIZE_T, WN_SIZE_T);
    typedef WN_VOID  (*WNScriptAlignedFree)(WN_VOID*);
    typedef WN_VOID* (*WNScriptMemcpy)(WN_VOID*, const WN_VOID*, WN_SIZE_T);

    class WNScriptingEngine {
    public:
        struct WNParameter {
            WNTypeElement mType;

            union {
                WN_SIZE_T mSizetVal;
                WN_UINT32 mUint32Val;
                WN_INT32 mInt32Val;
                WN_INT64 mInt64val;
                WN_FLOAT32 mFloatVal;
                WN_FLOAT64 mDoubleVal;
            };
        };

        virtual WN_BOOL AddExternalFunction(WN_VOID* _funcPtr, WN_BOOL _stackRet, const WN_CHAR* _returnType, const WN_CHAR* _name, const WN_CHAR* _arglist) = 0;
        virtual WN_BOOL RunFunction(const WN_CHAR* _file, const WN_CHAR* _functionName, const std::vector<WNParameter>& _params, WNParameter& _outParam) = 0;
        virtual WN_VOID CompileFunction(WNFunction* _func) = 0;
    
        virtual WN_BOOL Initialize() = 0;
        virtual WN_VOID DumpModule() = 0;
        virtual WNParameter CreateParameter(WN_CHAR* _type) = 0;
        virtual WN_VOID SetMallocFunction(WNScriptAllocFunc _scriptFunc) = 0;
        virtual WN_VOID SetFreeFunction(WNScriptFreeFunc _freeFunc) = 0;
        virtual WN_VOID SetMemcpyFunction(WNScriptMemcpy _memcpyFunc) = 0;
    };
    
    extern WN_SIZE_T WNGetScriptingEngineSize();
    extern WNScriptingEngine* WNCreateScriptingEngine(WN_VOID* _location = WN_NULL);
    extern WN_VOID WNDestroyScriptingEngine(WNScriptingEngine* _engine);
}
#endif // __WN_SCRIPTING_SCRIPTING_ENGINE_H__